#include "Piso.h"

#include <glm\gtc\matrix_transform.hpp>


Piso::Piso() : m_rotarEscalera(true) { }


void Piso::init(const glm::vec3 &posFuenteLuzDireccional, std::string vertShaderFileName, std::string fragShaderFileName){
	this->m_losa.init(posFuenteLuzDireccional, vertShaderFileName, fragShaderFileName);
	this->m_columna.init(posFuenteLuzDireccional, vertShaderFileName, fragShaderFileName);
	this->m_escalera.init(posFuenteLuzDireccional, vertShaderFileName, fragShaderFileName);
}


void Piso::setMaterial(const glm::vec3 &coefDifusion, const glm::vec3 &coefAmbiente, const glm::vec3 &coefEspecular) {
	this->m_losa.setMaterial( glm::vec3(0.7f, 0.45f, 0.45f), glm::vec3(0.225f, 0.1625f, 0.1625f), glm::vec3(0.0f, 0.0f, 0.0f) );
	this->m_columna.setMaterial( glm::vec3(0.25f, 0.5f, 0.5f), glm::vec3(0.0625f, 0.125f, 0.125f), glm::vec3(0.0f, 0.0f, 0.0f) );
	this->m_escalera.setMaterial( glm::vec3(0.8f, 0.3f, 0.05f), glm::vec3(0.05f, 0.015f, 0.0025f), glm::vec3(0.0f, 0.0f, 0.0f) );
}


void Piso::renderizar(const glm::mat4 &matVista, const glm::mat4 &matProyeccion, const glm::mat4 &matModelo) const {
	// El "piso" esta a 3 de altura
	glm::mat4 matModelPiso = glm::translate(matModelo, glm::vec3(0.0f, 0.0f, 3.0f));
	this->m_losa.renderizar(matVista, matProyeccion, matModelPiso);

	// Son 6 columnas a ubicar
	glm::mat4 matTransCol = glm::translate( matModelo, glm::vec3(4.0f, -9.0f, 0.0f) );
	this->m_columna.renderizar(matVista, matProyeccion, matTransCol);

	matTransCol = glm::translate( matModelo, glm::vec3(-4.0f, -9.0f, 0.0f) );
	this->m_columna.renderizar(matVista, matProyeccion, matTransCol);

	matTransCol = glm::translate( matModelo, glm::vec3(4.0f, 9.0f, 0.0f) );
	this->m_columna.renderizar(matVista, matProyeccion, matTransCol);

	matTransCol = glm::translate( matModelo, glm::vec3(-4.0f, 9.0f, 0.0f) );
	this->m_columna.renderizar(matVista, matProyeccion, matTransCol);

	matTransCol = glm::translate( matModelo, glm::vec3(4.0f, 0.0f, 0.0f) );
	this->m_columna.renderizar(matVista, matProyeccion, matTransCol);

	matTransCol = glm::translate( matModelo, glm::vec3(-4.0f, 0.0f, 0.0f) );
	this->m_columna.renderizar(matVista, matProyeccion, matTransCol);

	// Las escaleras y su rotacion
	glm::mat4 matTransEscaleras = glm::mat4(1.0f);

	if (this->m_rotarEscalera){
		matTransEscaleras = glm::translate(matModelo, glm::vec3(3.25f, -6.25f, 0.0f));
		matTransEscaleras = glm::rotate(matTransEscaleras, 180.0f, glm::vec3(0.0f, 0.0f, 1.0f));

	} else {
		matTransEscaleras = glm::translate(matModelo, glm::vec3(1.75f, -8.75f, 0.0f));
	}

	this->m_escalera.renderizar(matVista, matProyeccion, matTransEscaleras);
}


void Piso::rotarEscaleras(bool r) const {
	this->m_rotarEscalera = r;
}

